package cn.apthink.schedule;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import cn.apthink.calendar.Department;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProductHelper {
	private List<Product> lstProduct;
		
	public Product get(String productId) {
		Optional<Product> o = lstProduct.stream().filter(x -> {
			return x.getId().equals(productId);
		}).findAny();
		if (!o.isPresent()) {
			throw new RuntimeException("产品id不存在");
		} else {
			return o.get();
		}					
	}

	public String getPid(String productId) {
		Product p = get(productId);
		return p.getPid();
	}
	
	public Product getParent(String productId) {
		String pid = getPid(productId);
		return Objects.isNull(pid)?null:get(pid);
	}
	
	public static ProductHelper testData() {
		ProductHelper helper = new ProductHelper();
		helper.setLstProduct(Product.testDatas());
		return helper;
	}
}
